home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
cmln0886.arc
/
SCHEME2.LTG
< prev
next >
Wrap
Text File
|
1986-04-21
|
896b
|
28 lines
;;; FIB.S
;;; Recursive procedure for computing Fibonacci numbers in
;;; PC SCHEME. The Fibonnaci function is defined:
;;; FIB(n) = FIB(n - 1) + FIB(n - 2), for n > 1;
;;; FIB(n) = 1, for n = 1;
;;; FIB(n) = 1, for n = 0.
;;; EQ? could be replaced by = and T could be replaced
;;; by ELSE.
(define (fib n)
(cond ((eq? N 0) 1) ;;; N = 0 ?
((eq? N 1) 1) ;;; N = 1 ?
(T (+ (fib (- n 1)) ;;; Recurse.
(fib (- n 2)))))) ;;; Recurse.
(define (timed-fib-recurse N)
(define start-time (runtime))
(define found-fib (fib n))
(define elapsed-time (- (runtime) start-time))
(print N)
(cond (found-fib
(print " TIME IN MICROSECONDS ")
(print elapsed-time))))